package org.easy.db;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @Description:
 * @Author: wxl
 * @CreateTime: 2022/10/31 17:28
 */
public class ConnectManager implements IConnectManager{

    private static final Map<String, DataBaseFactory> CACHE = new ConcurrentHashMap<>();

    /**
     * 添加连接管理
     * @param dataBaseName 数据库名
     * @param factory     jdbc
     */
    @Override
    public synchronized void put(String dataBaseName, DataBaseFactory factory) {
        CACHE.put(dataBaseName, factory);
    }

    /**
     * 删除连接
     *
     * @param dataBaseName 数据库名
     */
    @Override
    public synchronized void remove(String dataBaseName) {
        CACHE.remove(dataBaseName);
    }

    /**
     * 获取JDBC
     *
     * @param dataBaseName 数据库名
     * @return DataBaseConnectTemplate
     */
    @Override
    public synchronized DataBaseFactory get(String dataBaseName) {
        return CACHE.get(dataBaseName);
    }

}
